package com.volcreate.inn.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.volcreate.inn.mapper.UserMapper;
import com.volcreate.inn.po.User;
import com.volcreate.inn.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zxc
 * @since 2020-08-23
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public User checkUser(String username, String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper
                .eq("username", username)
//                .eq("password", MD5Utils.code(password));
                .eq("password", password);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public String returnSpaceByNickname(String nickname) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper
                .eq("nickname", nickname);
        User user = userMapper.selectOne(wrapper);
        if (user != null) {
            return "//space.volcreate.com/" + user.getId();
        } else {
            return null;
        }
    }

    @Override
    public int register(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User getByUsername(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper
                .eq("username", username);
        User user = userMapper.selectOne(wrapper);
        return user;
    }
}
